package com.tuo51.core.domain.staffs;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tuo51.core.domain.org.Organization;
import com.tuo51.foudation.constant.CommonConstant;
import com.tuo51.foudation.model.Domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;

/**
 * *******************************
 * Created by Ron.
 * form com.tuo51
 * on 2017/7/10
 * *******************************
 */
@Data
@Entity
@Table(name = "staff", uniqueConstraints = {
        @UniqueConstraint(columnNames = {
                "source_appid", "unionid"
        })
})
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Staff extends Domain {
    /////  用户基础信息
    @Column(columnDefinition = "varchar(20) COMMENT '手机号唯一'")
    private String mobile;

    @Column(columnDefinition = "varchar(50) COMMENT '真实姓名'")
    private String realName;

    //微信获取的信息
    @Column(name = "nickname")
    private String nickName;

    @Column(name = "sex_desc")
    private String sexDesc;

    @Column
    private Integer sex = 0;

    @Column(name = "head_img_url")
    private String headImgUrl;

    @Column(name = "openid_mp",columnDefinition = "varchar(32) COMMENT '公众号openid'", unique = true)
    private String openidMP;

    @Column(name = "openid_ma",columnDefinition = "varchar(32) COMMENT '小程序openid'", unique = true)
    private String openidMA;

    @Column(name = "unionid",columnDefinition = "varchar(32) COMMENT '联合id'")
    private String unionid;

    @Column(name = "session_key")
    private String sessionKey;

    @Column(name = "source_appid", columnDefinition = "varchar(32) COMMENT '来源appid'")
    private String sourceAppId;

    // 系统信息
    @Column(columnDefinition = "int default 4 COMMENT '平台'")
    private int platform = CommonConstant.Platform.WXMA.codeOf();

    @Column(columnDefinition = " int DEFAULT 0 COMMENT '是否是admin账号，管理员等级' ")
    private int admin = 0;

    @JsonIgnore
    @OneToOne(mappedBy = "staff")
    StaffExtInfo extInfo;

    @Column(name = "org_id", columnDefinition = "varchar(32) COMMENT '机构id'")
    private String orgId;

    @JsonIgnore
    @OneToOne
    @JoinColumn(name = "org_id", insertable = false, updatable = false)
    Organization org;

    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '临时账号 0：否，1是' ")
    private Boolean temporally = false;
}
